﻿var status = 0;
var icon = "#fUI/Basic.img/BtMin2/normal/0#";
var iconX = "#fEffect/CharacterEff/1112905/0/1#";
var iconStar = "#fEffect/CharacterEff/1112904/2/1#";
var icon1 = "#fEffect/CharacterEff/1042176/0/0#";
var iconHR = "#fEffect/CharacterEff/1082565/0/0#"
var icon2 = "#fEffect/CharacterEff/1082565/2/0#";
var icon3 = "#fEffect/CharacterEff/1082565/4/0#";
var icon4 = "#fUI/UIWindow2.img/QuestAlarm/BtQ/normal/0#";
var giftContent = Array(
  //Array("余额兑换点卷：1余额=3000点",   1, Array(
     //   Array(-1, 3000)
   //)), 
 // Array("余额兑换点卷：10余额=30000点",   10, Array(
     //   Array(-10, 30000)
 //  )), 
  // Array("神秘椅子箱子（50）",   50, Array(
      //     Array(2431256, 1)
   // )), 
  // Array("名片戒指箱子（20）",  20, Array(
   //        Array(2432228, 1)
  //  )), 
  ..  Array("充值大礼包（10）",   10, Array(
        Array(2049124, 1),
        Array(2049116, 1),
		Array(-1, 10000)
    )), 
    Array("充值大礼包（50）",   50, Array(
        Array(2431987, 1),
        Array(2049124, 2),
        Array(2049116, 2),
        Array(2049752, 1),
        Array(2049313, 1),
        Array(-1, 50000)
    )), 
    Array("充值大礼包（100）",  100, Array(
        Array(2431987, 2),
        Array(2049124, 5),
        Array(2049116, 5),
        Array(2049313, 1),
        Array(2049752, 2),
        Array(3010659, 1),
        Array(3010608, 1),
        Array(1142178, 1),
        Array(2431944, 1),
        Array(-1, 100000)
    )),
    Array("充值大礼包（300）",  300, Array(
        Array(2431987, 4),
        Array(2049124, 25),
        Array(2049116, 25),
        Array(2049313, 2),
        Array(2049751, 2),
        Array(3010659, 1),
        Array(3010608, 1),
        Array(3010590, 1),
        Array(1142178, 1),
        Array(1112915, 1),
        Array(2431988, 1),
        Array(1182016, 1),
        Array(1132243, 1),
        Array(1122264, 1),
        Array(1032220, 1),
        Array(1113072, 1),
        Array(-1, 300000)
    )),
    Array("充值大礼包（600）", 600, Array(
        Array(2431990, 3),
        Array(2049124, 50),
        Array(2049116, 50),
        Array(2049313, 4),
        Array(2049750, 2),
        Array(3010661, 1),
        Array(3010608, 1),
        Array(3010590, 1),
        Array(1142179, 1),
        Array(1112915, 2),
        Array(2431938, 1),
        Array(2431991, 1),
        Array(2432069, 1),
        Array(2431988, 2),
        Array(2431995, 2),
        Array(1132244, 1),
        Array(1122265, 1),
        Array(2431509, 1),
        Array(1182016, 1),
        Array(-1, 700000)
    )),
    Array("充值大礼包（1000）", 1000, Array(
        Array(2431990, 5),
        Array(2049137, 50),
        Array(2049116, 50),
        Array(2049142, 50),
        Array(2049313, 8),
        Array(2049750, 4),
        Array(1112140, 1),
        Array(1112787, 1),
        Array(1003698, 1),
        Array(1672027, 1),
        Array(3010509, 1),
        Array(3700071, 1),
        Array(3010621, 1),
        Array(3010670, 1),
        Array(2431991, 2),
        Array(3010608, 1),
        Array(3010590, 1),
        Array(1142179, 1),
        Array(1112915, 3),
        Array(2431988, 4),
        Array(2431938, 1),
        Array(2432069, 2),
        Array(2431995, 4),
        Array(1032221, 1),
        Array(1113073, 1),
        Array(1132244, 1),
        Array(1122265, 1),
        Array(2431509, 1),
        Array(1182016, 1),
        Array(3010700, 1),
        Array(-1, 1500000)
    )),
    Array("充值大礼包（3000）", 3000, Array(
        Array(2431994, 5),
        Array(2049137, 100),
        Array(2049116, 100),
        Array(2049142, 100),
        Array(2049313, 16),
        Array(2049750, 6),
        Array(1112139, 1),
        Array(1112246, 1),
        Array(1112786, 1),
        Array(1003697, 1),
        Array(3010508, 1),
        Array(3700070, 1),
        Array(3010658, 1),
        Array(3010594, 1),
        Array(3010520, 1),
        Array(2431991, 1),
        Array(1142742, 1),
        Array(2431988, 4),
        Array(1672027, 1),
        Array(2432069, 4),
        Array(1132246, 1),
        Array(1122267, 1),
        Array(1032223, 1),
        Array(1113075, 1),
        Array(2431509, 2),
        Array(1182017, 1),
        Array(3010842, 1),
        Array(-1, 5000000)
    )),
    Array("充值大礼包（4000）", 4000, Array(
        Array(2431994, 5),
        Array(2049153, 100),
        Array(2049116, 100),
        Array(2049119, 100),
        Array(2049349, 16),
        Array(2049750, 6),
        Array(1112138, 1),
        Array(1112245, 1),
        Array(1112785, 1),
        Array(1003696, 1),
        Array(3010507, 1),
        Array(3700069, 1),
        Array(1672027, 1),
        Array(3015130, 1),
        Array(3016000, 1),
        Array(3010832, 1),
        Array(2431991, 1),
        Array(2431988, 2),
        Array(2432069, 6),
        Array(1142742, 1),
        Array(1142594, 1),
        Array(2431988, 8),
        Array(1132246, 1),
        Array(1122267, 1),
        Array(1032223, 1),
        Array(1113075, 1),
        Array(2431509, 4),
        Array(1182017, 1),
        Array(3010723, 1),
        Array(3010843, 1),
        Array(3014005, 1),
        Array(-1, 8000000)
    ))
    //Array("蜡笔礼包", 500, Array(
        //Array(3994417, 1),
        //Array(3994418, 1),
        //Array(3994419, 1),
        //Array(3994420, 1),
        //Array(3994421, 1),
        //Array(3994422, 1)
    //))
);
var giftId = -1;
var gifts = null;
var price = 999;
var column = new Array("装备", "消耗", "设置", "其他", "商城");
function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    }
    if (mode == 1) {
        status++;
    } else {
        status--;
    }
    if (status == 0) {
        var text = "";
		text = ""+iconHR+"尊敬的玩家#b#h ##k，欢迎来到#b#e充值礼包商城，点击可以查看礼包内容哦！#n#k\r\n";
        //text += "#e#b欢迎来到充值礼包商城，点击可以查看礼包内容哦！\r\n";
		text += ""+icon2+"您当前余额为：#r"+cm.getHyPay(1)+"#k "+"\t\t"+icon2+"累计充值：#r"+cm.getHyPay(3)+"#k\r\n";
        for(var key in giftContent) {
            text+="#b#L"+key+"#购买【#r#e"+giftContent[key][0]+"#n#b】 #e#d需要"+giftContent[key][1]+"余额#n#b#l#k\r\n";
        }
        cm.sendSimple(text);
    } else if (status == 1) {
        giftId = parseInt(selection);
        price = giftContent[giftId][1];
        gifts = giftContent[giftId][2];
        var text="#r#e"+giftContent[giftId][0]+"#n#b内容：\r\n";
        for(var key in gifts) {
            var itemId = gifts[key][0];
            var itemQuantity = gifts[key][1];
            text+="#i"+itemId+":##b" + (itemId == -1 ? "赠送点券" : "#z" + itemId + "#") + "#k #rx "+itemQuantity+"#k\r\n";
        }
        text+="\r\n#d是否花费#e#r"+price+"#n#d余额购买该礼包？#k";
        cm.sendYesNo(text);
    } else if (status == 2) {
        if (giftId!=-1 && gifts != null) {
            var needslot = new Array(0, 0, 0, 0, 0);
            for (var i in gifts) {
                var type = Math.floor(gifts[i][0] / 1000000);
                if (type == -1) {
                    continue;
                }
                needslot[type - 1] = needslot[type - 1] + 1;
            }
            for (var i = 0; i < 5; i++) {
                if (cm.getSpace(i + 1) < needslot[i]) {
                    cm.sendOk("您的" + column[i] + "栏位空间不足" + needslot[i] + "格，请清理后再来。");
                    cm.dispose();
                    return;
                }
            }
            if (cm.getHyPay(1) < price) {
                cm.sendOk("您的余额不足，请先充值后再购买。");
                cm.dispose();
                return ;
            }
            for(var key in gifts) {
                var itemId = gifts[key][0];
                var itemQuantity = gifts[key][1];
                if (itemId == -1) {
                    cm.gainNX(itemQuantity);
                } else {
                    cm.gainItem(itemId, itemQuantity);
                }
            }
            cm.addHyPay(price);
            cm.sendOk("恭喜您，购买成功！");
            cm.dispose();
        } else {
            cm.sendOk("购买错误！请联系管理员！");
            cm.dispose();
        }
    }
}